package com.njworkorder.Controller;

import com.njworkorder.DTO.AssignmentWithDiseaseDto;
import com.njworkorder.Entity.AssignmentWithDisease;
import com.njworkorder.Service.AssignmentWithDiseaseService;
import com.njworkorder.Utils.Result;
import com.njworkorder.Utils.ResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

@Tag(name = "病害登记和任务关联管理", description = "病害登记和任务关联信息相关接口")
@RestController
@RequestMapping("/AWD")
public class AssignmentWithDiseaseController {

    private final AssignmentWithDiseaseService AWDService;
    public AssignmentWithDiseaseController(AssignmentWithDiseaseService assignmentWithDiseaseService) {
        this.AWDService = assignmentWithDiseaseService;
    }

    @Operation(summary = "根据id更新病害登记和任务关联信息")
    @PostMapping("/updateAWDInfoById/{id}")
    public Result<String> updateAWDInfoById(@RequestBody AssignmentWithDiseaseDto assignmentWithDiseaseDto, @PathVariable("id") String id){
        AssignmentWithDisease AWD = new AssignmentWithDisease();
        AWD.setId(id);
        BeanUtils.copyProperties(assignmentWithDiseaseDto,AWD);
        boolean b = AWDService.updateById(AWD);
        if (b){
            return ResultUtil.success("更新成功");
        }
        return ResultUtil.error("更新失败");
    }

    @Operation(summary = "根据id获取病害登记和任务关联信息")
    @GetMapping("/getAWDInfoById")
    public Result<AssignmentWithDisease> getAWDInfoById(@RequestParam("id") String id){
        AssignmentWithDisease AWD = AWDService.getById(id);
        return ResultUtil.success(AWD);
    }

    @Operation(summary = "根据id删除病害登记和任务关联信息")
    @GetMapping("/deleteAWDInfoById")
    public Result<String> deleteAWDInfoById(@RequestParam("id") String id){
        boolean b = AWDService.removeById(id);
        if (b){
            return ResultUtil.success("删除成功");
        }
        return ResultUtil.error("删除失败");
    }


}
